// pages/edit/edit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    danger: null,

  },
  test() {
    console.log(this.data.id);
    console.log(this.data.danger);
  },
  datecharge(e) {
    this.setData({
      'danger.date': e.detail
    })
  },
  namecharge(e) {
    this.setData({
      'danger.name': e.detail
    })
  },
  inputNumcharge(e) {
    this.setData({
      'danger.inputNum': e.detail
    })
  },
  outputNumcharge(e) {
    this.setData({
      'danger.outputNum': e.detail
    })
  },
  handleNumcharge(e) {
    this.setData({
      'danger.handleNum': e.detail
    })
  },
  handleCompaincharge(e) {
    this.setData({
      'danger.handleCompain': e.detail
    })
  },
  back() {
    wx.navigateBack()
  },
  prickfile() {
	 let app = getApp();
	 let that=this;
    wx.chooseMessageFile({
      count: 1,
      type: "file",
      success: (res) => {
			console.log(res.tempFiles[0].name);
        wx.uploadFile({
          filePath: res.tempFiles[0].path,
			 name: 'file',
          url: app.globalData.ip + 'file/upload/'+res.tempFiles[0].name+'/'+that.data.danger.name,
          success: (res) => {
				 console.log(res.data);
				 let data=JSON.parse(res.data);
				 console.log(data.code);
            if (data.code == 200) {
				 	
				  wx.redirectTo({
					 url: '/pages/edit/edit?id='+that.data.danger.id,
				  })	  
            } else {
              app.show("上传失败");
            }
          }
        })
      }
    })
  },

  update() {
    let app = getApp();
    let that = this;
    wx.request({
      url: app.globalData.ip + 'd/setone',
      data: that.data.danger,
      method: "POST",
      success: (result) => {
        if (result.data.code == 200) {
			 app.show("修改成功");
        } else {
			 app.show("修改失败");
        }
      },
      fail: (err) => {
        app.show("修改失败")
      }
    })
  },
  toinsert() {
    wx.navigateTo({
      url: '/pages/update/update',
    })
  },
  getdata(id) {
    let that = this;
    let app = getApp();
    wx.request({
      url: app.globalData.ip + 'd/getonebyid/' + id,
      success: (res) => {
        let md = res.data.data;

        const newdanger = {
          id: md.id,
          name: md.name,
          outputNum: Number(md.outputNum),
          inputNum: Number(md.inputNum),
          handleNum: Number(md.handleNum),
          handleCompain: md.handleCompain,
          date: md.date
        };
        that.setData({
          danger: newdanger
        });

      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.id;
    this.getdata(options.id);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})